/*
 * Main1.fx
 *
 * Created on Jul 31, 2009, 2:21:24 PM
 */
package com.gpsbuddy.main;

import com.gpsbuddy.utils.Utils;
import javafx.scene.Scene;
import javafx.stage.Stage;
import com.gpsbuddy.utils.DatabaseUtils;
import com.gpsbuddy.navigation.FrontPage;
import com.gpsbuddy.navigation.PositionPage;
import com.gpsbuddy.navigation.ServiceOptionsPage;
import com.gpsbuddy.navigation.SettingsPage;
import com.gpsbuddy.navigation.FriendsPage;

/**
 * @author jonycus
 */
var stage: Stage;
def profile = Utils.initialize("{__PROFILE__}");
var dbInitialized: Boolean = DatabaseUtils.initiliazeDatabase();
var env: Enviroment;
def multiplicator: Integer = Utils.getMultiplicator();
public var renderHomeButton: Boolean = false;
var currentScene: Scene;

function run()         {
    if (javafx.stage.Screen.primary.visualBounds.width >= 600 or javafx.stage.Screen.primary.visualBounds.height >= 600) {
        env = Enviroment { screenWidth: 600 screenHeight: 600 };
    } else {
        env = Enviroment {
            screenWidth: javafx.stage.Screen.primary.visualBounds.width as Integer
            screenHeight: javafx.stage.Screen.primary.visualBounds.height as Integer
        };
    }
    stage = Stage {
        width: bind env.screenWidth;
        height: bind env.screenHeight;
        title: "Application title"
        scene: bind currentScene;
        onClose: function()  {
            DatabaseUtils.storeData()
        };
    }
    switchToFrontPage();
}

public function switchToPosition() {
    renderHomeButton = true;
    var positionScene = PositionPage {
                multiplicator: bind multiplicator;
                env: env;
            }
    currentScene = positionScene;
    positionScene.transitIn();
}

public function switchToServiceOptions() {
    renderHomeButton = true;
    var serviceOptionsPage = ServiceOptionsPage {
                env: env;
                mainBarHeight: bind env.screenHeight;
                mainBarWidth: bind env.screenWidth;
            }
    currentScene = serviceOptionsPage;
    serviceOptionsPage.transitIn();
}

public function switchToFrontPage() {
    renderHomeButton = false;
    var frontScene = FrontPage {
                env: env;
            };
    if (currentScene != null) {
        frontScene.transitIn();
    }
    currentScene = frontScene;
}

public function switchToSettingsPage() {
    renderHomeButton = true;
    var settingsPage = SettingsPage {
                env: env;
            }
    currentScene = settingsPage;
    settingsPage.transitIn();
}

public function switchToFriendsPage() {
    renderHomeButton = true;
    var friendsPage = FriendsPage {
                env: env;
            }
    currentScene = friendsPage;
    friendsPage.transitIn();
}








